import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Date;

public class Log {
    /**
     * 记录操作日志
     */
    public static void record(String operationType, String description, String operator) {
        String sql = "INSERT INTO operation_logs (operation_type, description, operator, operation_time) " +
                "VALUES (?, ?, ?, ?)";

        try (Connection conn = DBUtil.getConnection();
             PreparedStatement pstmt = conn.prepareStatement(sql)) {

            pstmt.setString(1, operationType);
            pstmt.setString(2, description);
            pstmt.setString(3, operator);
            pstmt.setTimestamp(4, new java.sql.Timestamp(new Date().getTime()));

            pstmt.executeUpdate();
        } catch (SQLException e) {
            System.err.println("记录日志失败: " + e.getMessage());
        }
    }
}
